package com.guojian.http;

import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.smartboot.http.HttpBootstrap;

import com.guojian.http.handle.route.HttpJettyRouteHandle;
import com.guojian.http.handle.route.HttpSmartRouteHandle;

public class Http {

	public static void main(String[] args) {
		try {
			Server server = new Server();
			//DefaultHandler defaultHandler = new DefaultHandler();
			//ContextHandler defaultHandler = new ContextHandler();
			HttpJettyRouteHandle routeHandle = new HttpJettyRouteHandle();
			server.setHandler(routeHandle);

			ServerConnector connector = new ServerConnector(server);
			connector.setPort(9080);
			connector.setIdleTimeout(3330000);
			server.setConnectors(new Connector[] { connector });
			server.start();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * smart-http 服务启动
	 */
	public static void smartHttp() {
		// 1. 实例化路由Handle
		HttpSmartRouteHandle routeHandle = new HttpSmartRouteHandle();
		// 3. 启动服务
		HttpBootstrap bootstrap = new HttpBootstrap();
		bootstrap.pipeline().next(routeHandle);
		bootstrap.setPort(9080).start();
	}

}
